package ONLINE_EXAM;

import java.util.HashMap;
import java.util.Map;

class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }

}

public class bd2 {
    /**
     * 遍历当前链表 将当前结点存在hashmap中
     *
     * @param head
     * @return
     */
    public boolean judge(ListNode head) {
        if (head == null || head.next == null ){
            return false;
        }
       ListNode pre = null;
        ListNode cur = head;

        Map<ListNode, ListNode> map = new HashMap<>();//key存前结点 value存当前结点

        while (!map.containsKey(pre)){
            map.put(pre,cur);
            pre =cur;
            if (null != cur.next){
                cur = cur.next;
            } else {
                return false;
            }
        }
        return true;

    }
}
